<template>
  <div class="app-container">
    <div class="list-view">
      <!-- <el-table v-loading="loading" :data="taskList">
        <el-table-column
          label="序号"
          align="center"
          prop="noticeId"
          width="100"
        >
          <template #default="scope">
            <span>{{
              scope.$index +
              1 +
              (queryParams.pageDomain.pageNum - 1) *
                queryParams.pageDomain.pageSize
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="阶段标题"
          align="center"
          prop="missionName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="公告类型"
          align="center"
          prop="noticeType"
          width="100"
        >
          <template #default="scope">
            <dict-tag
              :options="sys_notice_type"
              :value="scope.row.noticeType"
            />
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status" width="100">
          <template #default="scope">
            <dict-tag :options="sys_notice_status" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column
          label="创建者"
          align="center"
          prop="createBy"
          width="100"
        />
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          width="100"
        >
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template #default="scope">
            <el-button
              link
              type="primary"
              icon="Control"
              @click="goDetail(scope.row)"
              >查看详情</el-button
            >
          </template>
        </el-table-column>
      </el-table> -->
      <!-- <div>
        <el-row v-for="item in taskList" :key="item.id" class="list-row">
          <el-col :span="24">
            <el-row class="title">
              <el-col :span="20">{{ item.missionName }}</el-col>
              <el-col :span="4">
                <el-button
                  link
                  type="primary"
                  icon="Edit"
                  @click="goDetail(item)"
                  >查看详情</el-button
                ></el-col
              >
            </el-row>
            <el-row class="intro" :gutter="28"
              ><el-col :span="6"
                >开始时间：{{ item.startTime }}</el-col
              >
              <el-col :span="6"
                >结束时间：{{ item.endTime }}</el-col
              ></el-row
            >
          </el-col>
        </el-row>
      </div> -->
      <div class="task-tab">
        <div v-for="item in taskList" :key="item.id" @click="goDetail(item)" :class="{active:item.id == activeTaskId}">
          {{ item.missionName }}
        </div>
      </div>
      <!-- <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      /> -->
    </div>
    <!-- <TaskDetail
      :taskId="activeTaskId"
      @back="showList()"
      v-model="dialogVisible"
    ></TaskDetail> -->
    <TaskDetail
      :taskId="activeTaskId"
      @back="showList()"
      v-if="activeTaskId"
    ></TaskDetail>
  </div>
</template>

<script setup >
import {
  listNotice,
  getNotice,
  delNotice,
  addNotice,
  updateNotice,
} from "@/api/system/notice";
import { getStageList } from "@/api/pms/project";
import TaskDetail from "./taskDetail.vue";

const props = defineProps({
  projectId: {
    type: String,
  },
});
const route = useRoute();
const router = useRouter();

const { proxy } = getCurrentInstance();
const { sys_notice_status, sys_notice_type } = proxy.useDict(
  "sys_notice_status",
  "sys_notice_type"
);

const taskList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const listShow = ref(true);
const activeTaskId = ref("");
const dialogVisible = ref(false);

const data = reactive({
  form: {},
  queryParams: {
    pageDomain: {
      isAsc: "true",
      orderByColumn: "",
      pageNum: 1,
      pageSize: 10,
      reasonable: true,
    },
    id: props.projectId,
    name: "1",
  },
  rules: {
    noticeTitle: [
      { required: true, message: "公告标题不能为空", trigger: "blur" },
    ],
    noticeType: [
      { required: true, message: "公告类型不能为空", trigger: "change" },
    ],
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询公告列表 */
function getList(i) {
  loading.value = true;
  getStageList(queryParams.value).then((response) => {
    taskList.value = response.rows;
    total.value = response.total;
    loading.value = false;
    if(i&& i == 'init'){
      activeTaskId.value = taskList.value[0].id
    }
  });
}

/**跳转活动详情 */
function goDetail(row) {
  activeTaskId.value = row.id;
  // listShow.value = false;
  // dialogVisible.value = true;
}
function showList() {
  activeTaskId.value = "";
  listShow.value = true;
}

onMounted(() => {
  getList('init');
});
</script>
<style scoped lang="scss">
.list-row {
  padding: 10px 0;
  margin: 10px 0;
  border-bottom: 1px dashed #cccccc;
  .title {
    padding: 10px 0;
  }
  .intro {
    color: #cccccc !important;
  }
}
.task-tab {
  display: flex;
  flex-wrap: wrap;
  div {
    margin: 10px 20px;
    padding: 10px 40px;
    background: #EFEFEF;
    color: #494342;
    cursor: pointer;
    border-radius: 6px;
    &.active{
      background: #EDF5FF;
      color: #046DED;
    }
  }
}
</style>